#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

void push(void);
void pop(void);
void pal(void);
void disp(void);

int  i,top=-1;
char str[30],list[30],opt='E',c;

void main()
{
  while     (opt!='X')
 {
  clrscr();
  printf("------STACK---------\n");
  printf("<A> . . . Push\n");
  printf("<P> . . . Pop\n");
  printf("<V> . . . View\n");
  printf("<D> . . . Check palindrome\n");
  printf("<X> . . . Exit\n");
  printf("\nChoice:");
  opt=toupper(getch());
  putchar(opt);
  printf("\n\n");
  switch (opt)
       {
	case 'A' : push(); break;
	case 'P' : pop(); break;
	case 'V' : printf("\n");disp();break;
	case 'D' : pal(); break;
	case 'X' : break;
	default  : printf("\nError! Invalid Choice.Try Again."); getch();break;
       }
  }
}

void push(void)
{
 if (top==30) {
		printf("\nSTACK  FULL");
		getch();
		return;
	    }
 printf("\nCharacter:");
 list[++top]=getche();
 printf("        Continue <Y/N>?");
 if(toupper(getche())!='N')
   push();
}

void pop(void)
{
 if (top==-1) {
		printf("\nStack empty.");
		getch();
		return;
	    }
  printf("\n%c detected on top of the stack. Pop Item?<Y/N>",list[top]);
 if (toupper(getche())=='Y') list[top--]='\x0';
 printf("        Continue <Y/N>?");
 if(toupper(getche())!='N')
   pop();
}

void pal(void)
{
 if (top==-1) {
		printf("Stack empty.");
		getch();
		return;
	      }
 for (i=0;i<=top+1;i++) str[i]='\x0';
 for(i=top;i>=0;i--)  str[top-i]=list[i];
  if (strcmpi(str,list)==0) printf("\nIs a Palindrome.");
 else printf("\nNot a Palindrome.");
 getch();
}

void disp(void)
{
 if (top==-1) {printf("Stack Empty");getch();return;}
 for(i=top;i>=0;i--) printf("%c",list[i]);
 getch();
}